package com.mycom.controller;

import com.mycom.controller.constant.Code;
import com.mycom.controller.entity.Result;
import com.mycom.pojo.FormItem;
import com.mycom.service.FormItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/formItems")
public class FormItemController {
    @Autowired
    private FormItemService formItemService;

    @PutMapping
    public Result update(@RequestBody List<FormItem> formItems){
        boolean flag = true;
        for (FormItem formItem : formItems) {
            flag  = flag & formItemService.update(formItem);
        }
        Integer code = flag ? Code.UPDATE_SUCCESS : Code.UPDATE_ERR;
        String msg = flag ? "修改报表工作项成功" : "修改报表工作项失败";
        return new Result(code,flag,msg);
    }
    @DeleteMapping("/{id}")
        public Result deleteById(@PathVariable Integer id){
            boolean flag = formItemService.deleteById(id);
            Integer code = flag ? Code.DELETE_SUCCESS : Code.DELETE_ERR;
            String msg = flag ? "删除报表工作项成功" : "删除报表工作项失败";
            return new Result(code,flag,msg);
    }
}
